<?php

namespace Modules\Web\Http\Controllers;

use HiCommon\Service\MenuService;
use HiCommon\Service\PlatformBusinessAgreementService;
use Illuminate\Http\Request;
use HiCommon\Service\CommonService;
use Modules\Web\Service\PublicService;

use SimpleSoftwareIO\QrCode\Facades\QrCode;
use Storage;


class PublicController extends BaseController
{

    public function access_permissions()
    {
        $n_uid = intval(web_user_id());
        $result = MenuService::api_menu_shop_app($n_uid);
        return hello_success('成功', $result);

    }

    /**
     *  获取所有省份信息列表
     *  hinq 2019 11 21
     *
     **/
    public function get_address_list(Request $request)
    {
        $arr_input = (array)$request->all();
        $arr_list = PublicService::get_address_list((array)$arr_input);
        return response_json($arr_list);
    }


    /**
     * 根据城市编码获取城市信息
     */
    public function get_city_infor(Request $request)
    {
        $city = $request->all();
        $arr_list = PublicService::get_city_infor($city);

        return response_json($arr_list);
    }

    /**
     * 获取已经开通的城市
     */
    public function get_province_list()
    {
        $arr_list = PublicService::getProvinceList();

        return response_json($arr_list);
    }

    /**
     *市区二级联动
     */
    public function get_area_list(Request $request)
    {
        $cid = $request->all();

        return PublicService::getCityAraeList($cid);
    }

    /**
     * 计算两个地理点的距离
     *
     * @return array|void
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function location_distance_for_two_point()
    {
        try {
            $arr_input = \Illuminate\Support\Facades\Request::input();
            return CommonService::api_location_distance($arr_input);
        } catch (\Exception $exception) {
            return ['state' => 1, 'msg' => '失败', 'data' => [], 'error' => $exception->getMessage()];
        }
    }

    /**
     * 获取快递公司列表
     */
    public function get_express_list()
    {
        $list = PublicService::get_express_list();
        return response_json($list);
    }

    /**
     * 商家服务协议列表
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function business_agreement_list()
    {
        try {
            $arr_input = \Illuminate\Support\Facades\Request::input();
            $res = PlatformBusinessAgreementService::api_list($arr_input);
            if( !$res ){
                $res = defaule_Protocol_list('6','商家服务协议');
            }
            return hello_success('成功', $res);
        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }
    }

    /**
     * 商家服务协议详情
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function business_agreement_detail()
    {
        try {
            $n_id = intval(\Illuminate\Support\Facades\Request::input('id', 0));
            $res = PlatformBusinessAgreementService::api_detail($n_id);
            return hello_success('成功', $res);

        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }
    }

    /**
     * 物流追踪
     * 2019 11 15
     */
    public function logistics_tracking(Request $request)
    {
        $order_id = intval($request->get('order_id', 0));
        $type = intval($request->get('type', 0));

        $res = PublicService::logistics_tracking($order_id, $type);

        return response_json($res);
    }

    /**
     * 生成二维码
     */
    public function create_qr_code(Request $request)
    {
        $order_id = intval($request->get('order_id', 0));
        $type = $request->get('type');

        $res = PublicService::create_qr_code($order_id, $type);

        return $res;
    }

}